package com.example.springboot.mapper;

import com.example.springboot.entity.notifications;
import com.example.springboot.entity.students;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface NotificationMapper {

    @Select("SELECT * FROM notifications WHERE notification_id = #{notification_id}")
    notifications getNotificationById(int notification_id);

    @Select("SELECT * FROM notifications")
    List<notifications> getAllNotifications();

    @Insert("INSERT INTO notifications (user_id, sender_id, title, message, created_at, read_status) VALUES (#{user_id}, #{sender_id}, #{title}, #{message}, NOW(), #{read_status})")
    @Options(useGeneratedKeys = true, keyProperty = "notification_id")
    void insertNotification(notifications notification);

    @Update("UPDATE notifications SET title = #{title}, message = #{message}, read_status = #{read_status} WHERE notification_id = #{notification_id}")
    void updateNotification(notifications notification);

    @Delete("DELETE FROM notifications WHERE notification_id = #{notification_id}")
    void deleteNotification(int notification_id);

    @Delete("<script>" +
            "DELETE FROM notifications WHERE notification_id IN " +
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    void deleteNotifications(@Param("ids") List<Integer> ids);



    @Select("SELECT\n" +
            "\tuser_id, \n" +
            "\t`name`\n" +
            "FROM\n" +
            "\tstudents")
    List<students> findStuList();

    @Delete({
            "<script>",
            "DELETE FROM notifications WHERE notification_id IN ",
            "<foreach item='notification_id' collection='list' open='(' separator=',' close=')'>#{notification_id}</foreach>",
            "</script>"
    })
    void batchDeleteN(List<Long> ids);
}
